import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_example/get_put/controller/my_put_controller.dart';

class MyObxPage extends StatelessWidget {
  static const String route = "/MyObxPage";

  const MyObxPage({super.key});

  @override
  Widget build(BuildContext context) {
    //Int
    RxInt count = 0.obs;
    var count1 = 0.obs;

    //String
    RxString audi = "Audi".obs;
    var audi1 = "Audi".obs;

    //List
    RxList<String> list = ["Audi", "BMW", "Mercedes"].obs;
    var list1 = ["Audi", "BMW", "Mercedes"].obs;

    //Map
    RxMap<String, String> map = {"Audi": "Audi", "BMW": "BMW", "Mercedes": "Mercedes"}.obs;
    var map1 = {"Audi": "Audi", "BMW": "BMW", "Mercedes": "Mercedes"}.obs;

    //Models
    RxList<GetXModels> models = [GetXModels(name: "Audi"), GetXModels(name: "BMW"), GetXModels(name: "Mercedes")].obs;
    var models1 = [GetXModels(name: "Audi"), GetXModels(name: "BMW"), GetXModels(name: "Mercedes")].obs;

    //Model
    Rx<GetXModels> model = GetXModels(name: "Audi").obs;
    var model1 = GetXModels(name: "Audi").obs;

    //GetXRxModels
    RxList<GetXRxModels> rxModels =
        [GetXRxModels(name: "Audi".obs), GetXRxModels(name: "BMW".obs), GetXRxModels(name: "Mercedes".obs)].obs;
    var rxModels1 =
        [GetXRxModels(name: "Audi".obs), GetXRxModels(name: "BMW".obs), GetXRxModels(name: "Mercedes".obs)].obs;

    //bool
    RxBool isTrue = true.obs;
    var isTrue1 = true.obs;

    updateCount() {
      count.value++;
      count1.value++;
    }

    updateAudi() {
      audi.value = "BMW";
      audi1.value = "BMW";
    }

    updateList() {
      list[0] = "BMW";
      list1[0] = "BMW";
    }

    updateMap() {
      map["Audi"] = "BMW";
      map1["Audi"] = "BMW";
    }

    updateModels() {
      models[0] = GetXModels(name: "BMW");
      models1[0] = GetXModels(name: "BMW");
    }

    updateModel() {
      model.value = GetXModels(name: "BMW");
      model1.value = GetXModels(name: "BMW");
    }

    updateRxModels() {
      rxModels[0].name.value = "BMW";
      rxModels1[0].name.value = "BMW";
    }

    updateIsTrue() {
      isTrue.value = !isTrue.value;
      isTrue1.value = !isTrue1.value;
    }

    updateAll() {
      updateCount();
      updateAudi();
      updateList();
      updateMap();
      updateModels();
      updateModel();
      updateRxModels();
      updateIsTrue();
    }

    return Scaffold(
      appBar: AppBar(
        title: const Text("Get(Obx)"),
      ),
      body: Center(
        child: Obx(() => Column(
              children: [
                Text("int -> $count"),
                Text("int -> $count1"),
                const Divider(),
                Text("String -> $audi"),
                Text("String -> $audi1"),
                const Divider(),
                Text("list -> $list"),
                Text("list -> $list1"),
                const Divider(),
                Text("map -> $map"),
                Text("map -> $map1"),
                const Divider(),
                Column(
                  children: models.map((element) {
                    return Text("element -> ${element.name}");
                  }).toList(),
                ),
                const Divider(),
                Column(
                  children: models1.map((element) {
                    return Text("element -> ${element.name}");
                  }).toList(),
                ),
                const Divider(),
                Text("model -> ${model.value.name}"),
                Text("model -> ${model1.value.name}"),
                const Divider(),
                Column(
                  children: rxModels.map((element) {
                    return Text("element -> ${element.name}");
                  }).toList(),
                ),
                const Divider(),
                Column(
                  children: rxModels1.map((element) {
                    return Text("element -> ${element.name}");
                  }).toList(),
                ),
                const Divider(),
                Text("bool -> $isTrue"),
                Text("bool -> $isTrue1"),
                const Divider(),
                ElevatedButton(
                  onPressed: () {
                    updateAll();
                  },
                  child: const Text('add'),
                ),
              ],
            )),
      ),
    );
  }
}
